package com.ktgj.service.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.service.mapper.OrderOperationlogMapper;
import com.ktgj.service.domain.OrderOperationlog;
import com.ktgj.service.service.IOrderOperationlogService;

/**
 * 订单操作记录
Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@Service
public class OrderOperationlogServiceImpl implements IOrderOperationlogService 
{
    @Autowired
    private OrderOperationlogMapper orderOperationlogMapper;

    /**
     * 查询订单操作记录

     * 
     * @param operationId 订单操作记录
ID
     * @return 订单操作记录

     */
    @Override
    public OrderOperationlog selectOrderOperationlogById(Long operationId)
    {
        return orderOperationlogMapper.selectOrderOperationlogById(operationId);
    }

    /**
     * 查询订单操作记录
列表
     * 
     * @param orderOperationlog 订单操作记录

     * @return 订单操作记录

     */
    @Override
    public List<OrderOperationlog> selectOrderOperationlogList(OrderOperationlog orderOperationlog)
    {
        return orderOperationlogMapper.selectOrderOperationlogList(orderOperationlog);
    }

    /**
     * 新增订单操作记录

     * 
     * @param orderOperationlog 订单操作记录

     * @return 结果
     */
    @Override
    public int insertOrderOperationlog(OrderOperationlog orderOperationlog)
    {
        orderOperationlog.setCreateTime(DateUtils.getNowDate());
        return orderOperationlogMapper.insertOrderOperationlog(orderOperationlog);
    }

    /**
     * 修改订单操作记录

     * 
     * @param orderOperationlog 订单操作记录

     * @return 结果
     */
    @Override
    public int updateOrderOperationlog(OrderOperationlog orderOperationlog)
    {
        return orderOperationlogMapper.updateOrderOperationlog(orderOperationlog);
    }

    /**
     * 批量删除订单操作记录

     * 
     * @param operationIds 需要删除的订单操作记录
ID
     * @return 结果
     */
    @Override
    public int deleteOrderOperationlogByIds(Long[] operationIds)
    {
        return orderOperationlogMapper.deleteOrderOperationlogByIds(operationIds);
    }

    /**
     * 删除订单操作记录
信息
     * 
     * @param operationId 订单操作记录
ID
     * @return 结果
     */
    @Override
    public int deleteOrderOperationlogById(Long operationId)
    {
        return orderOperationlogMapper.deleteOrderOperationlogById(operationId);
    }

    @Override
    public int insertRecord(OrderOperationlog orderOperationlog) throws Exception {
        if (orderOperationlog.getMemo() != null && !orderOperationlog.getMemo().equals("")){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            orderOperationlog.setOperationName("添加操作记录");
            orderOperationlog.setOperationType(EmHelper.OperationType.Employee.getValue());
            try {
                orderOperationlog.setCreateTime(format.parse(format.format(new Date())));
            } catch (Exception e){
                throw new Exception("日期转换错误");
            }
            orderOperationlog.setOperationResult("true");
            int i = orderOperationlogMapper.insertOrderOperationlog(orderOperationlog);
            return i;
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }


}
